﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Pegasus.UnitTests
{
    [TestClass]
    public class ExceptionHelperTests
    {
        private const string TEST_STR = "a test string";
        private const int TEST_INT = 5;
        private const bool TEST_BOOL = true;

        [TestMethod]
        public void ExceptionHelperTest()
        {
            try
            {
                throw new TestException( TEST_STR, TEST_INT, TEST_BOOL );
            }
            catch( Exception ex )
            {
                string dump = ExceptionHelper.DumpExceptionAll( ex );
                Assert.IsTrue( dump.Contains( string.Format( "TestFieldStr: {0}", TEST_STR ) ) );
                Assert.IsTrue( dump.Contains( string.Format( "TestFieldInt: {0}", TEST_INT ) ) );
                Assert.IsTrue( dump.Contains( string.Format( "TestFieldProp: {0}", TEST_BOOL ) ) );
                Assert.IsTrue( !dump.Contains( "m_testFieldProp" ) );
            }
        }

        public class TestException : Exception
        {
            public string TestFieldStr;
            public int TestFieldInt;
            private bool m_testFieldProp;

            public bool TestFieldProp
            {
                get
                {
                    return m_testFieldProp;
                }
                set
                {
                    m_testFieldProp = value;
                }
            }

            public TestException( string testStr, int testInt, bool testBool )
            {
                TestFieldStr = testStr;
                TestFieldInt = testInt;
                m_testFieldProp = testBool;
            }
        }
    }
}
